//
// Created by gogoqiu on 2021/10/12.
//

#ifndef RAPIDSVN_CMAKE_LISTVIEWADAPTER_H
#define RAPIDSVN_CMAKE_LISTVIEWADAPTER_H

#include <vector>
#include "wx/wx.h"
//#include "BaseViewHolder.h"
//#include "../librapidsvn/include/action_event.hpp"

using namespace std;
/**
 * ui线程
 * template:
 *  extends ViewHolder
 */
template< class DataType, class BaseViewHolder >
class ListViewAdapter {
protected:
    /*
     * new Adapter
     * RecycledView::setAdapter
     * adapter::append
     * ViewHolder
     * ListBox
     * createView
     */
    /*
     * mListViewAdapter = new ListViewAdapter();
     * //connect
     * //bind it, insert the OnFrameGetItems function to the event callback
     * //Bind(wxEVT_BUTTON, &MyFrame::OnQuitButton, this, ID_BUTTON_QUIT);
     * onCreateViewHolder
     * onBindViewHolder
     */
    /*
     *
     * */
    vector<DataType*> items;
    //wxDialog* parent;
    wxWindow* parent;
    //wxWindow *p;
public:
    static const int ID_DATA_SET_CHANGED = 5555;
    static const int ID_ITEM_RANGE_INSERTED = 5556;
    ListViewAdapter( wxWindow*, wxScrolledWindow* );

    //request in the thread, notifyDataSetChanged the item to ui thread
    //支持异步实现
    void clearItemsWithNotify();

    //action side, client side, thread side
    void setItemsWithNotify (  vector<DataType*> infos );

    void appendItemsWithNotify (  vector<DataType*> infos );

    virtual int getItemViewType ( int position )
    {
        //return super.getItemViewType(position);
        return 0;
    }

    virtual void onBindViewHolder ( BaseViewHolder* holder, int position );
    virtual void onBindViewHolder( BaseViewHolder *holder,
                                   DataType* date );
    //wxFrame
    //ui thread side
    virtual BaseViewHolder* onCreateViewHolder ( int viewType, DataType * data );

    int getItemCount(){
        return items.size();
    }

    int position = 0;

    //


    //OnEvent
    //static void OnEvent();

    //ui thread side
    void OnFrameGetItems( int startPosition, vector<DataType*> items );
protected:
    /*
     * post items to ui thread?
     * 如何封装信息
     * ui thread how to handle the event
     */
    //action side, client side, thread side
    //post items to the ui
    void notifyDataSetChanged();

    //void notifyItemRangeInserted( int startPosition, vector<DataType> items );

    void notifyItemRangeInserted( int startPosition, int itemCount );

    //EVT_MENU ( ACTION_EVENT, MainFrame::OnActionEvent )
    void OnActionEvent ( wxCommandEvent & event );

    //
    struct Item_range_inserted_package;
    /**
     * recyclerView.setAdapter(adapter);
     */
    wxScrolledWindow* m_listbox;
private:

};


#endif //RAPIDSVN_CMAKE_LISTVIEWADAPTER_H
